package com.lzc.springboot.mapper;

import com.lzc.springboot.domain.Farmer;
import org.apache.ibatis.annotations.*;

@Mapper
public interface FarmerMapper {

  /**
   * 根据用户ID查询农户
   * @param uid
   * @return
   */
  @Select("select * from farmer where uid=#{uid}")
  @Options(useCache = false,flushCache = Options.FlushCachePolicy.TRUE)
  Farmer findFarmerByUid(int uid);

  /**
   * 修改农户信息
   * @param farmer
   */
  @Update("update farmer set name = #{name}, sex = #{sex}, phone = #{phone}, email = #{email}, address = #{address} where id=#{id}")
  void changeFarmer(Farmer farmer);

  /**
   * 查询所有农户
   * @return
   */
  @Select("select * from farmer")
  @Options(useCache = false,flushCache = Options.FlushCachePolicy.TRUE)
  Farmer[] findAllFarmer();

  /**
   * 查询所有农户
   * @return
   */
  @Select("select * from farmer where name like concat('%',#{name},'%') and phone like concat('%',#{phone},'%') and email like concat('%',#{email},'%')")
  @Options(useCache = false,flushCache = Options.FlushCachePolicy.TRUE)
  Farmer[] findFarmerByText(Farmer farmer);

  /**
   * 根据农户ID查询农户
   * @param fid
   * @return
   */
  @Select("select * from farmer where id=#{fid}")
  Farmer findFarmerByFid(int fid);

  /**
   * 根据农户ID删除农户
   * @param id
   */
  @Delete("delete form farmer where id=#{id}")
  void delFarmerById(int id);

  /**
   * 添加农户
   * @param farmer
   */
  @Insert("insert into farmer values(null,#{name},#{sex},#{phone},#{email},#{address},#{uid})")
  void addFarmer(Farmer farmer);
}
